package net.xiduth.game.player.dialogues.tutorial;

import net.xiduth.cores.CoresManager;
import net.xiduth.game.WorldTile;
import net.xiduth.game.player.Player;
import net.xiduth.game.player.content.FadingScreen;
import net.xiduth.game.player.content.Magic;
import net.xiduth.game.player.dialogues.Dialogue;
import net.xiduth.utils.Logger;

/**
 * 
 * First tutorial.
 *
 */

public class CooksAssistant extends Dialogue {

	@Override
	public void start() {
	if (!player.isCook()) {
			sendNPCDialogue(278, 9827,
					"You're awake, "+player.getDisplayName()+"!");
			player.getHintIconsManager().removeUnsavedHintIcon();
		} else {
			sendNPCDialogue(278, 9827,
					"You're back!");
		}	
	}
	
	public void fade (final Player player) {
		final long time = FadingScreen.fade(player);
		CoresManager.slowExecutor.execute(new Runnable() {
		@Override
		public void run() {
		try {
		FadingScreen.unfade(player, time, new Runnable() {
		@Override
		public void run() {
		}
		});
		} catch (Throwable e) {
		Logger.handle(e);
		}
		}

		});
		}

	@Override
	public void run(int interfaceId, int componentId) {
		switch (stage) {
		case -1:
			if (!player.isCook()) {
				stage = 0;
				sendPlayerDialogue(9827, "Yeah.. where am I?");
			} else {
				stage = 11;
				sendPlayerDialogue(9827, "Yes, take these!");
			}
			break;
		case 0:
			sendNPCDialogue(278, 9827, "Are you drunk? It's Jae's birthday, and I don't have time "+"to get the ingredients!");
			stage = 1;
			break;
		case 1:
			sendNPCDialogue(278, 9827, "Could you help me "+player.getDisplayName()+"?");
			stage = 2;
			break;
		case 2:
		sendOptionsDialogue(SEND_DEFAULT_OPTIONS_TITLE,
					"Sure I can!", "Who are you?",
					"Sorry, im busy right now.", "Skip the tutorial.");
		case 3:
		switch (componentId) {
			case OPTION_1:
				sendPlayerDialogue(9827,
						"Of course I will help you!");
				stage = 4;
				break;
			case OPTION_2:
				sendPlayerDialogue(9827,
						"Who the hell are you?");
				stage = 5;
				break;
			case OPTION_3:
				stage = 69;
				sendPlayerDialogue(9827,
						"Sorry im busy right now.");
				break;
			case OPTION_4:
				player.getInventory().addItem(6099, 1);
				player.setDoneCombatTutorial();
				player.falseCombatTutorial();
				player.getControlerManager().removeControlerWithoutCheck();
				Magic.sendNormalTeleportSpell(player, 0, 0, new WorldTile(3682,
						2973, 0));
	            	player.getInterfaceManager().sendInterface(275);
					for (int i = 0; i < 310; i++) {
						player.getPackets().sendIComponentText(275, i, "");
						player.getPackets().sendIComponentText(275, 1, "Quest Complete!</col>");
						player.getPackets().sendIComponentText(275, 13, "You have finished the tutorial.");
						player.getPackets().sendIComponentText(275, 14, "Limits have been lifted.");
						player.getPackets().sendIComponentText(275, 16, "Teleport Crystal access.");
						}
					 player.getInterfaceManager().closeChatBoxInterface();
            stage = 69;
		}
			break;
		case 4:
			sendNPCDialogue(278, 9827, "Thank heavens!");
				stage = 6;
				break;
		case 5:
			sendNPCDialogue(278, 9827, "Are you out of your mind? I'm your personal cook!");
				stage = 7;
				break;
		case 6:
			sendNPCDialogue(278, 9827, "You will need 3 items for the cake, "+"an egg from the chickens east of here.");
			stage = 8;
			break;
		case 7:
			sendPlayerDialogue(9827, "What is going on...");
			stage = 69;
			break;
		case 8:
			sendNPCDialogue(278, 9827, "You can get a pot of flour from Fred the farmer, "+ "north of here.");
			stage = 9;
			break;
		case 9:
			sendNPCDialogue(278, 9827, "Lastly, you can get a bucket of milk from "+"Gillie Groats. She is with the cows.");
			stage = 10;
			break;
		case 10:
			sendNPCDialogue(278, 9827, "Take this pot and give it to Fred!");
			player.getInventory().addItem(1931, 1);
			player.setCook();
			stage = 69;
			break;
		case 11:
			if (player.getInventory().containsItem(1933, 1)
				&& player.getInventory().containsItem(1944, 1)
				&& player.getInventory().containsItem(1927, 1)) {
			sendNPCDialogue(278, 9827,
			"Thanks, "+player.getDisplayName()+"!");
			stage = 12;
			} else { 
			sendNPCDialogue(278, 9827,
					"Do not tell me you have the ingredients when you don't. "+"Leave!");
			player.getPackets().sendGameMessage("Remember, " + player.getDisplayName() + ". You need 3 items for the cake... an <col=C12006>egg</col> from the chickens in the Lumbridge farm, a <col=C12006>Pot of flour</col> from Farmer Freddy, and a <col=C12006>Bucket of milk</col> from Gillie Groat.");
			stage = 69;
			}
			break;		
		case 12:
			player.getInventory().deleteItem(1933, 1);
			player.getInventory().deleteItem(1944, 1);
			player.getInventory().deleteItem(1927, 1);
				sendNPCDialogue(278, 9827, "I have something to tell you though...");
					stage = 13;
					break;
		case 13:
			sendNPCDialogue(278, 9827, "It's... not Jae's Birthday.");
				stage = 14;
				break;
		case 14:
			sendPlayerDialogue(9827, "WHAT!? WHY DID YOU MAKE ME GET THOSE INGREDIENTS THEN!?");
				stage = 15;
				break;
		case 15:
			sendNPCDialogue(278, 9827, "I had to see if I could trust you for another quest.");
				stage = 16;
				break;
		case 16:
			sendNPCDialogue(278, 9827, "This next quest is much more serious.");
				stage = 17;
				break;
		case 17:
			sendNPCDialogue(278, 9827, "You should pay Ozan a visit.");
				stage = 18;
				break;
		case 18:
			    player.getInterfaceManager().closeChatBoxInterface();
            	player.getInterfaceManager().sendInterface(275);
				for (int i = 0; i < 310; i++) {
					player.getPackets().sendIComponentText(275, i, "");
					player.getPackets().sendIComponentText(275, 1, "Quest Complete!");
					player.getPackets().sendIComponentText(275, 13, "2 Spins on the squeal!");
					player.getPackets().sendIComponentText(275, 14, "25k coins & 100 Teleport Crystals (check your bank)!");
					player.getPackets().sendIComponentText(275, 16, "Speak with Ozan for your next mission.");
					}
					player.getInventory().addItem(24155 ,1);
					player.getInventory().addItem(995 , 25000);
					player.getBank().addItem(6099, 100, true);
					player.setDoneCook();
					player.falseCook();
                stage = 69;
                break;
		case 69:
			end();
			break;
	}
}

		@Override
	public void finish() {
		// TODO Auto-generated method stub

	}
}